/**
* Created by Jimmy on 2017/7/16.
*/
<template>
    <div class="survey-item-content">

      <el-button type="danger" icon="el-icon-close" size="mini" circle @click="deleteSelf"></el-button>

      <!--<button type="button" class="btn btn-warning btn-xs operate" v-on:click="deleteSelf">-->
        <!--<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>-->
      <!--</button>-->
      <div class="column-warp">
        <select v-model="survey_item.major_selected">
          <option :value = "i" v-for="(sub, i) in survey_item.majors">
            {{  sub.name }}
          </option>
        </select>
      </div>
      <div class="column-warp">
        <select v-model="survey_item.project_selected">
          <option :value = "i" v-for="(sub, i) in survey_item.majors[survey_item.major_selected].projects">
            {{  sub.name }}
          </option>
        </select>
      </div>

      <div class="column-warp">
        <select v-model="survey_item.sub_project_selected">
          <option :value = "i" v-for="(sub, i) in survey_item.majors[survey_item.major_selected].projects[survey_item.project_selected].sub_projects">
            {{  sub.name }}
          </option>
        </select>
      </div>

      <div class="column-warp">
        <select v-model="survey_item.level_selected">
          <option :value = "i" v-for="(sub, i) in survey_item.majors[survey_item.major_selected].projects[survey_item.project_selected].sub_projects[survey_item.sub_project_selected].levels">
            {{  sub.name }}
          </option>
        </select>
      </div>
      <div class="column-warp">
        <span>{{ survey_item.majors[survey_item.major_selected].projects[survey_item.project_selected].sub_projects[survey_item.sub_project_selected].levels[survey_item.level_selected].unit }}</span>
      </div>
      <div class="column-warp">
        <span>{{ survey_item.majors[survey_item.major_selected].projects[survey_item.project_selected].sub_projects[survey_item.sub_project_selected].levels[survey_item.level_selected].prices[hard_degree] }}</span>
      </div>
      <div class="column-warp">
        <input type="text" placeholder="系(根)数" v-model.number="survey_item.majors[survey_item.major_selected].projects[survey_item.project_selected].sub_projects[survey_item.sub_project_selected].levels[survey_item.level_selected].coefficient"/>
      </div>
      <div class="column-warp">
        <input type="text" placeholder="数量" v-model.number="survey_item.majors[survey_item.major_selected].projects[survey_item.project_selected].sub_projects[survey_item.sub_project_selected].levels[survey_item.level_selected].quantity"/>
      </div>
      <div class="column-warp">
        <span>{{ survey_item.majors[survey_item.major_selected].projects[survey_item.project_selected].sub_projects[survey_item.sub_project_selected].levels[survey_item.level_selected].total }}</span>
      </div>
      <div class="column-warp">
        <input type="text" placeholder="说明" v-model.number="survey_item.majors[survey_item.major_selected].projects[survey_item.project_selected].sub_projects[survey_item.sub_project_selected].levels[survey_item.level_selected].description"/>
      </div>
      <div class="column-warp">
        <span>{{ survey_item.majors[survey_item.major_selected].projects[survey_item.project_selected].sub_projects[survey_item.sub_project_selected].levels[survey_item.level_selected].reference }}</span>
      </div>
    </div>
</template>

<script>
  export default {
    props: {
      index: Number,
      hard_degree: String,
      survey_item: Object
    },
    watch: {
      hard_degree: function (newdegree) {
        this.survey_item.majors[this.survey_item.major_selected].projects[this.survey_item.project_selected].sub_projects[this.survey_item.sub_project_selected].levels[this.survey_item.level_selected].total = this.calculateTotal(this.survey_item, newdegree)
      },
      survey_item: {
        handler: function (newitem) {
          this.survey_item.majors[this.survey_item.major_selected].projects[this.survey_item.project_selected].sub_projects[this.survey_item.sub_project_selected].levels[this.survey_item.level_selected].total = this.calculateTotal(newitem, this.hard_degree)
        },
        deep: true
      }
    },
    methods: {
      calculateTotal: function (newitem, newdegree) {
        var coefficient = newitem.majors[newitem.major_selected].projects[newitem.project_selected].sub_projects[newitem.sub_project_selected].levels[newitem.level_selected].coefficient
        var price = newitem.majors[newitem.major_selected].projects[newitem.project_selected].sub_projects[newitem.sub_project_selected].levels[newitem.level_selected].prices[newdegree]
        var quantity = newitem.majors[newitem.major_selected].projects[newitem.project_selected].sub_projects[newitem.sub_project_selected].levels[newitem.level_selected].quantity
        return (coefficient * price * quantity).toFixed(2)
      },
      deleteSelf: function () {
        this.$emit('deleteSurveyItem', this.index)
      }
    }
  }
</script>

<style scoped>
  .survey-item-content{
    height: 30px;
    /*background: red;*/
    text-align: left;
    margin: 10px 0;
    display: flex;
    flex-flow: row;
    line-height: 30px;
  }
  .el-button.is-circle{
    /*width: 28px;*/
    height: 28px;
    /*margin-top: 6px;*/
  }
  .operate{
    /*flex: 0 0 20px;*/
    color: white;
    height: 20px;
    margin: 5px 10px 5px 0;
  }
  .column-warp{
    flex-grow: 1;
    flex-basis: 0;
    flex-shrink: 0;
    margin: 0 5px;
    height: 30px;
    text-align: center;
    /*border: 1px solid black;*/
  }
  .column-warp:last-of-type{
    margin-right: 0;
  }
  .column-warp select{
    outline: none;
    height: 30px;
    width: 100%;
    overflow: hidden;
  }
  .survey-item-content input{
    outline: none;
    width: 100px;
    line-height: 25px;
    padding:  0 10px;
    border: 1px solid #ededed;
  }
  .survey-item-content input:focus{
    border: 1px solid #e74c3c;
  }
</style>
